import com.sun.org.apache.regexp.internal.RE;

import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.*;

public class Test {

    @org.junit.Test
    public void testClase() {
        TestClase testClase = new TestClase();
    }



    @org.junit.Test
    public void test() {
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(5);
        list.add(0);
        list.add(1);
        list.add(4);
        Collections.sort(list);
        System.out.println(list.get(2));
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        Thread t = new Thread(myThread);
        t.start();

        Thread.sleep(3000);
        myThread.setGoal(true);
//        myThread.setNum(1);
    }

    static class MyThread implements Runnable {

        private volatile int num = 0;
        private boolean goal = false;

        public boolean isGoal() {
            return goal;
        }

        public void setGoal(boolean goal) {
            this.goal = goal;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }

        @Override
        public void run() {
            while (true) {
//                try {
//                    Thread.sleep(1);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                if (goal) {
                    System.out.println("Goal!");
                    setGoal(false);
                }
            }
        }
    }
}

class TestClase {
    int i = 1;
    {
        System.out.println(++i);
        print("构造块");
    }


    TestClase() {
        print("构造函数");
    }


    public void print(String str) {
        System.out.println(str + (++i));
    }
}

